﻿<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JavaScript捕获方向键</title>
  <script type="text/javascript" language="JavaScript">
    function check(){
      if(event.keyCode === "37")
        alert("您选择了左键！");
      if(event.keyCode === "38")
        alert("您选择了上键！");
      if(event.keyCode === "39")
        alert("您选择了右键！");
      if(event.keyCode === "40")
        alert("您选择了下键！");
    }
  </script>
</head>
<body onkeydown="check()">

</body>
</html>